package com.onluy.frameworkcloud.tools.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 

public class CookieUtil {

	
	public static String getCookeValue(HttpServletRequest request ,String key) { 
		if(key==null)return null;
		String value=null;
		javax.servlet.http.Cookie[] cookes= request.getCookies();
		if(cookes==null)return null;
		for(int i=0;i<cookes.length;i++){    //用一个循环语句遍历刚才建立的Cookie对象数组 
			javax.servlet.http.Cookie sCookie=cookes[i];   //取出数组中的一个Cookie对象 
			if(key.equals(sCookie.getName())){
				value=sCookie.getValue(); //取得这个Cookie的内容 
			break;
			}
		}
		return value;
	}
	
	public static void setCookeValue(HttpServletResponse response ,String key,String value) {  
		javax.servlet.http.Cookie  cookie = new javax.servlet.http.Cookie(key,value);
		response.addCookie(  cookie);  
	}
	
	
}
